package tech.anzhen.simple.rpc.support.rest;

import org.apache.http.HttpHost;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class RestConnectionSocketFactory extends PlainConnectionSocketFactory {

    private static final RestConnectionSocketFactory INSTANCE = new RestConnectionSocketFactory();

    public static RestConnectionSocketFactory instance() {
        return INSTANCE;
    }

    private Logger logger = LoggerFactory.getLogger(RestConnectionSocketFactory.class);

    @Override
    public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host, InetSocketAddress remoteAddress,
                                InetSocketAddress localAddress, HttpContext context) throws IOException {
        logger.info("开始连接远程地址: {}", remoteAddress);
        return super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
    }

}
